<%@ page contentType="text/html; charset=utf-8" language="java"    pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>蛋糕后台</title>
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript">
		
			jQuery(function(){
				var breadId="${bread.id}";
				if(breadId==""){
					changeBigClass();
				}
			});
			
		
			function addBread(){
				var name=jQuery('#name').val();
				var code=jQuery('#code').val();
				var content=jQuery('#content').val();
				var heavy=jQuery('#heavy').val();
				var size=jQuery('#size').val();
				var stock=jQuery('#stock').val();
				var taste=jQuery('#taste').val();
				var big_class_id=jQuery('#big_class_id').val();
				var small_class_id=jQuery('#small_class_id').val();
				var condition=jQuery('#condition').val();
				var people=jQuery('#people').val();
				var sendTime=jQuery('#sendTime').val();
				var price=jQuery('#price').val();
				if(big_class_id==""){
					alert("请选择大类");
					return ;
				}
				if(small_class_id==""){
					alert("请选择小类");
					return ;
				}
				
				var breadId="${bread.id}";
				jQuery.post("addBread",{name:name,code:code,content:content,heavy:heavy,size:size,stock:stock,taste:taste,big_class_id:big_class_id,small_class_id:small_class_id,condition:condition,people:people,sendTime:sendTime,price:price,breadId:breadId,r:Math.random()},function(json){
					if(json.success==1){
						 alert('操作成功');
						 location.href="admin_bread";
					}else{
						 alert('失败了，稍后重试');
					}
				},"json");
			}
			
			function changeBigClass(){
				var big_class_id=jQuery('#big_class_id').val();
				if(big_class_id==""){
					jQuery('#small_class_id').find("option").remove();
					return ;
				}
				jQuery.post("selectSmallClass",{big_class_id:big_class_id,r:Math.random()},function(json){
					if(json.success==1){
						jQuery('#small_class_id').find("option").remove();
						jQuery.each(json.smallClasses, function(i){
							jQuery('#small_class_id').append("<option value='"+this.id+"'>"+this.name+"</option>");
						});
					}else{
						 
					}
				},"json");
			}
			
			function del(id){
				if (!confirm("确定删除吗？")){
					return false;
			    }
				jQuery.post("delBread",{id:id,r:Math.random()},function(json){
					if(json.success==1){
						 alert('操作成功');
						 location.href="admin_bread";
					}else{
						 alert('失败了，稍后重试');
					}
				},"json");
			}
			 
			
		
		</script>
		<style type="text/css">
			<!--
			body,td,th {
				font-family: 宋体;
				font-size: 12px;
				color: #333333;
			}
			body {
				margin-left: 0px;
				margin-top: 0px;
			}
			-->
		</style>
    </head>
    <body>
        <table width="100%" border="1">
        	<tr>
        		<td bgcolor="#84FF84">名称:<input type="text" name="name" id="name" value="${bread.name }" /></td>
        		<td bgcolor="#84FF84">编号:<input type="text" name="code" id="code" value="${bread.code }"  /></td>
        	</tr>
        	<tr>
        		<td bgcolor="#84FF84" colspan="2">
	        		介绍:
	        		<textarea rows="3" cols="100" id="content" name="content" >${bread.content }</textarea>
        		</td>
        	</tr>
        	<tr>
        		<td bgcolor="#84FF84">重量:<input type="text" name="heavy" id="heavy" value="${bread.heavy }"  /></td>
        		<td bgcolor="#84FF84">尺寸:<input type="text" name="size" id="size" value="${bread.mySize }"  /></td>
        	</tr>
        	<tr>
        		<td bgcolor="#84FF84">原料:<input type="text" name="stock" id="stock" value="${bread.stock }"  /></td>
        		<td bgcolor="#84FF84">口味:<input type="text" name="taste" id="taste" value="${bread.taste }" /></td>
        	</tr>
        	<tr>
        		<td bgcolor="#84FF84">
        			所属大类:
        			<select name="big_class_id" id="big_class_id" onchange="changeBigClass()">
        				<option value="">请选择</option>
        				<c:forEach items="${bigClasses}" var="bigClass">
        					<option value="${bigClass.id }" <c:if test="${bread.bigClassId eq bigClass.id }">selected="selected"</c:if>>${bigClass.name }</option>
        				</c:forEach>
        			</select>
        		</td>
        		<td bgcolor="#84FF84">
        			所属小类:
        			<select name="small_class_id" id="small_class_id">
        				 <c:if test="${not empty bread.id}">
        				 	<c:forEach items="${smallClasses}" var="smallClass">
	        					<option value="${smallClass.id }" <c:if test="${bread.smallClassId eq smallClass.id }">selected="selected"</c:if>>${smallClass.name }</option>
	        				</c:forEach>
						</c:if>
        			</select>
        		</td>
        	</tr>
        	<tr>
        		<td bgcolor="#84FF84">保鲜条件:<input type="text" name="condition" id="condition" value="${bread.myCondition }" /></td>
        		<td bgcolor="#84FF84">适合人群:<input type="text" name="people" id="people" value="${bread.people }" /></td>
        	</tr>
        	<tr>
        		<td bgcolor="#84FF84">送货时间:<input type="text" name="sendTime" id="sendTime"  value="${bread.sendTime }"/></td>
        		<td bgcolor="#84FF84">价格:<input type="text" name="price" id="price" value="${bread.price }" />(格式:128.00元)</td>
        	</tr>
        	<tr>
        		<td bgcolor="#84FF84" colspan="2" align="center" ><a href="javascript:addBread()">点此保存</a></td>
        	</tr>
        </table>
        
        <table width="100%" border="1" style="margin-top: 50px;">
        	<tr>
        		<td>
        			<form action="admin_bread" method="get">
	        			名称：<input name="name" value=""/> &nbsp;&nbsp;
    	    			编号：<input name="code" value=""/> &nbsp;&nbsp;
    	    			<input type="submit" value="查询" />
        			</form>
        			
        		</td>
        	</tr>
        </table>
        
        <table width="100%" border="1">
        	<tr>
        		<td bgcolor="#84FF84">名称</td>
        		<td bgcolor="#84FF84">编号</td>
        		<td bgcolor="#84FF84">重量</td>
        		<td bgcolor="#84FF84">尺寸</td>
        		<td bgcolor="#84FF84">原料</td>
        		<td bgcolor="#84FF84">口味</td>
        		<td bgcolor="#84FF84">大类</td>
        		<td bgcolor="#84FF84">小类</td>
        		<td bgcolor="#84FF84">保鲜条件</td>
        		<td bgcolor="#84FF84">适合人群</td>
        		<td bgcolor="#84FF84">送货时间</td>
        		<td bgcolor="#84FF84">价格</td>
        		<td bgcolor="#84FF84">小图url</td>
        		<td bgcolor="#84FF84">大图url</td>
        		<td bgcolor="#84FF84">操作</td>
        	</tr>
        	<c:forEach items="${breads }" var="bread">
	        	<tr>
	        		<td bgcolor="#84FF84">${bread.name}</td>
	        		<td bgcolor="#84FF84">${bread.code}</td>
	        		<td bgcolor="#84FF84">${bread.heavy }</td>
	        		<td bgcolor="#84FF84">${bread.mySize }</td>
	        		<td bgcolor="#84FF84">${bread.stock }</td>
	        		<td bgcolor="#84FF84">${bread.taste }</td>
	        		<td bgcolor="#84FF84">${bread.bigClassId }</td>
	        		<td bgcolor="#84FF84">${bread.smallClassId }</td>
	        		<td bgcolor="#84FF84">${bread.myCondition }</td>
	        		<td bgcolor="#84FF84">${bread.people }</td>
	        		<td bgcolor="#84FF84">${bread.sendTime }</td>
	        		<td bgcolor="#84FF84">${bread.price }</td>
	        		<td bgcolor="#84FF84">${bread.smallPicUrl }</td>
	        		<td bgcolor="#84FF84">${bread.bigPicUrl }</td>
	        		<td bgcolor="#84FF84">
	        			<a href="javascript:del('${bread.id }')">删除</a>
	        			<a href="admin_bread?id=${bread.id }">更新</a>
	        			<a href="uploadPic?id=${bread.id }">上传图片</a>
	        			<a href="addPrice?id=${bread.id }">添加价格</a>
					</td>
	        	</tr>
        	</c:forEach>
        	<tr>
	        		<td height="40"  align="center" colspan="20">
		        		 <a href="admin_bread?pageNo=1&name=${name}&code=${code}" >首页</a>&nbsp;&nbsp;
		        		 <a href="admin_bread?pageNo=${pageNo-1 }&name=${name}&code=${code}" >上一页</a>&nbsp;&nbsp;
		        		 <a href="admin_bread?pageNo=${pageNo+1 }&name=${name}&code=${code}" >下一页</a>&nbsp;&nbsp;
		        		<a href="admin_base">点此返回</a>
	        		</td>
	        </tr>
        </table>
    </body>
</html>
